<?php
include('lib.php');

header('Content-Type:text/html;charset=GB2312');

try{
	if(isset($_GET['s'])){
		$site = $_GET['s'];
		$o = new $site;
		echo $o::getTitles();
	}elseif(isset($_GET['d'])){
		showDetail();
	}elseif(isset($_GET['p'])){
		//{{{请求图片
		$img = $_GET['img'];
		if(!$img) die();
		$info = getimagesize($img);

		if(!preg_match("/http:\/\/(.*?)\/.*(?:\/|\?)([^\/?]+.(?:jpg|gif|png))$/i", $img, $match)){
			die();
		}
		$referer = $_GET['referer'] ? $_GET['referer'] : $match[1];	
		$filename = $match[2];
		header("Content-Type:image/jpeg");
		header("Content-Type:{$info['mime']}\n");
		header("Content-Disposition:inline;filename={$filename}\n");


		$path = "img/{$referer}-{$filename}";
		if(file_exists($path)){
			readfile($path);
		}

		geturl($img, $referer);
		die();
		$im = imagecreatefromstring($rawdata);
		imagejpeg($im, $path);
		readfile($path);
		//}}}
	}else{
		throw new Exception ('hello');
	}
}catch(Exception $e){
	echo 'Sorry , I can not understand your request';
}
